/**
 * 
 */
package net.sf.tools.uiconfig.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import net.sf.tools.uiconfig.util.HierarchicalEntity;

/**
 * @author Sabuj Das | sabuj.das@gmail.com
 *
 */
public class Menu implements Comparable<Menu>, Serializable, HierarchicalEntity<Menu>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 16546346546L;
	private String menuName;
	private String label;
	private String targetUrl;
	private Integer displayOrder = 0;
	private boolean visible = true;
	private boolean enabled = true;
	private Configuration configuration;
	private Menu parentMenu;
	private List<Menu> subMenus;
	
	/**
	 * 
	 */
	public Menu() {
		this.subMenus = new ArrayList<Menu>(0);
	}
	
	public String getMenuName() {
		return menuName;
	}

	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getTargetUrl() {
		return targetUrl;
	}

	public void setTargetUrl(String targetUrl) {
		this.targetUrl = targetUrl;
	}

	public Integer getDisplayOrder() {
		return displayOrder;
	}

	public void setDisplayOrder(Integer displayOrder) {
		this.displayOrder = displayOrder;
	}

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public Configuration getConfiguration() {
		return configuration;
	}

	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	public Menu getParentMenu() {
		return parentMenu;
	}

	public void setParentMenu(Menu parentMenu) {
		this.parentMenu = parentMenu;
	}

	public List<Menu> getSubMenus() {
		return subMenus;
	}

	public void setSubMenus(List<Menu> subMenus) {
		this.subMenus = subMenus;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((menuName == null) ? 0 : menuName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Menu)) {
			return false;
		}
		Menu other = (Menu) obj;
		if (menuName == null) {
			if (other.menuName != null) {
				return false;
			}
		} else if (!menuName.equals(other.menuName)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "Menu [ " + menuName + " ]";
	}

	public int compareTo(Menu other) {
		if(null == other)
			return 1;
		return this.displayOrder.compareTo(other.displayOrder);
	}

	/**
	 * @return
	 */
	public boolean hasChildren() {
		return (null != subMenus && subMenus.size() > 0);
	}

	public Menu getParent() {
		return getParentMenu();
	}

	public List<Menu> getChildren() {
		return getSubMenus();
	}
	
}
